package cn.tedu.lucky.draw.user.handler;

import cn.tedu.lucky.draw.user.protocol.po.UserLog;
import cn.tedu.lucky.draw.user.service.IUserLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.reactive.function.server.ServerRequest;
import org.springframework.web.reactive.function.server.ServerResponse;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.util.List;

import static org.springframework.web.reactive.function.BodyInserters.fromPublisher;

@Component
public class UserLogHandler {

    @Autowired
    private IUserLogService userLogService;

    /**
     * @param serverRequest 代表一个HTTP请求，包含了请求头、请求参数、请求路径等信息
     * @return ServerResponse 代表一个HTTP响应，包含了响应头、响应体、响应状态码等信息
     */
    public Mono<ServerResponse> findAll(ServerRequest serverRequest){
//        获取请求头
        List<String> header = serverRequest.headers().header("Connection");
        System.out.println(header);
        Flux<UserLog> userLogFlux = userLogService.findAll();
        return ServerResponse.ok().body(fromPublisher(userLogFlux, UserLog.class));
    }
}
